<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="ookweb.Conn"%>
<%@ page import="ookweb.Data"%>
<%@ include file="../public.jsp" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ookweb/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">    
    <title>信息管理</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/images/m/css.css">
	<script src="<%=basePath%>js/jquery-1.5.1.min.js"  type="text/javascript" ></script>
	<script src="<%=basePath%>js/public.js"  type="text/javascript" ></script>
  </head>
  
  <body><br/>
  <%   Data data=new Data(dbuser,dbpass,dburl);
     Conn con=new Conn(dbuser,dbpass,dburl);
     String userid=(String)request.getParameter("userid");
    String act=(String)request.getParameter("act"); 
   
    //分页段 
     //变量声明 
String mysql=new String(); //SQL语句
mysql=" web_member ";
int intRowCount=0;  //总的记录数
int intPageCount=0; //总的页数
int intPageSize=15; //每页显示的记录数
int intPage; //待显示页码 
String strPage=new String(); //用来接收当页码参数
int begin_no=0; //开始的rownum记录号
int end_no=0;  //结束的rownum记录号

//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//得到总的数据记录行数
intRowCount=data.getRowCount(mysql); //总记录数

//计算总共要分多少页
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 

if(intPage>intPageCount) intPage = intPageCount; 
//分页段
     
    
    int intT=0;
    if("d".equals(act) && !("".equals(userid)) && userid!=null){
       data.delete("delete from web_member where mid="+userid);
       act=""; 
     }
    if(!("".equals(act) ||  act==null)){
       String USERNAME="",USERPASS="",TRUENAME="",COMPANY="",TELEPHONE="",EMAIL="",QUESTION="",ANSWER="",USERSTAT="";
      if("save".equals(act)){
          String sql="";
          USERNAME=(String)request.getParameter("USERNAME");
          USERPASS=(String)request.getParameter("USERPASS");
          TRUENAME=(String)request.getParameter("TRUENAME");
          COMPANY=(String)request.getParameter("COMPANY");
          TELEPHONE=(String)request.getParameter("TELEPHONE");
            EMAIL=(String)request.getParameter("EMAIL");
          QUESTION=(String)request.getParameter("QUESTION");
           ANSWER=(String)request.getParameter("ANSWER");
           USERSTAT=(String)request.getParameter("USERSTAT");
         int num=0;
         
         if(!("".equals(userid)) && userid!=null){
	         sql="update web_member set USERNAME='"+USERNAME+"',USERPASS='"+USERPASS+"',TRUENAME='"+TRUENAME+"',COMPANY='"+COMPANY+"',TELEPHONE='"+TELEPHONE+"',EMAIL='"+EMAIL+"',QUESTION='"+QUESTION+"',ANSWER='"+ANSWER+"',USERSTAT="+USERSTAT+" where mid="+userid;
	        out.print(sql);
	         num=data.update(sql);
	         if(num>0){out.print("<script>alert(\"已成功修改\");</script>");}
         }else{
         java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date currentTime=new java.util.Date();
         String time=formatter.format(currentTime);
         sql="insert into web_member(mid,USERNAME,USERPASS,TRUENAME,COMPANY,TELEPHONE,EMAIL,QUESTION,ANSWER,USERSTAT,addtime)values(WEB_MEMBER_SEQ.nextval,'"+USERNAME+"','"+USERPASS+"','"+TRUENAME+"','"+COMPANY+"','"+TELEPHONE+"','"+EMAIL+"','"+QUESTION+"','"+ANSWER+"',"+USERSTAT+",to_date('"+time+"','yyyy/mm/dd'))";
         out.print(sql);
         num=data.insert(sql);
         if(num>0){out.print("<script>alert(\"已成功添加\");</script>");}
          act="";
         }
         response.sendRedirect(basePath+"webadmin/member/user.jsp?page"+intPage);
      }else if("e".equals(act) && !("".equals(userid)) && userid!=null){	       
			 ResultSet rs=con.getRs("SELECT * FROM web_member where mid="+userid);
			 if(rs.next()){
			  USERNAME=rs.getString("USERNAME");
              USERPASS=rs.getString("USERPASS");
              TRUENAME=rs.getString("TRUENAME");
              COMPANY=rs.getString("COMPANY");
              TELEPHONE=rs.getString("TELEPHONE");
              EMAIL=rs.getString("EMAIL");
              QUESTION=rs.getString("QUESTION");
              ANSWER=rs.getString("ANSWER");
              USERSTAT=rs.getString("USERSTAT");
			 }
      }else{userid="";}
      %>
      <script src="<%=basePath%>ckeditor/ckeditor.js"  type="text/javascript" ></script>
      <script type="text/javascript" src="<%=basePath%>ckfinder/ckfinder.js"></script>
      
      <form action="<%=basePath%>webadmin/member/user.jsp?act=save&userid=<%=userid %>&page=<%=intPage %>" method="post" id="frm">
	  <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
	   <tr>
	    <td align="center" width="140">用户名</td>
	    <td align="left"><input name="USERNAME" id="USERNAME" style="width:400px;" type="text" class="inp" value="<%=USERNAME %>"/></td>
	  </tr>
	   <tr> 
	    <td align="center" width="140">密码</td>
	    <td align="left"><input name="USERPASS" id="USERPASS" style="width:400px;" type="text" class="inp" value="<%=USERPASS %>"/></td>
	  </tr>
	   <tr> 
	    <td align="center" width="140">真名</td>
	    <td align="left"><input name="TRUENAME" id="TRUENAME" style="width:400px;" type="text" class="inp" value="<%=TRUENAME %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">公司</td>
	    <td align="left"><input name="COMPANY" id="COMPANY" style="width:400px;" type="text" class="inp" value="<%=COMPANY %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">电话</td>
	    <td align="left"><input name="TELEPHONE" id="TELEPHONE" style="width:400px;" type="text" class="inp" value="<%=TELEPHONE %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">邮件</td>
	    <td align="left"><input name="EMAIL" id="EMAIL" style="width:400px;" type="text" class="inp" value="<%=EMAIL %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">密码找回问题</td>
	    <td align="left"><input name="QUESTION" id="QUESTION" style="width:400px;" type="text" class="inp" value="<%=QUESTION %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">密码找回答案</td>
	    <td align="left"><input name="ANSWER" id="ANSWER" style="width:400px;" type="text" class="inp" value="<%=ANSWER %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">状态</td>
	    <td align="left">
	       <select name="USERSTAT" id="USERSTAT">
  <option value="0" <%if("0".equals(USERSTAT)){out.print("selected");} %>>未审</option>
  <option value="1" <%if("1".equals(USERSTAT)){out.print("selected");} %>>已审</option>
  <option value="2" <%if("2".equals(USERSTAT)){out.print("selected");} %>>冻结</option>
</select>
	    </td>
	  </tr>
	   <tr>
	    <td align="center" width="140">操作</td>
	    <td align="left"> <input name="cmd" id="savecmd" type="button" class="inp" value="保存" style="width:60px;"/> <input name="cmd" id="cmdreturn" type="button" class="inp" value="返回" style="width:60px;"/></td>
	  </tr>
	 </table>
	 </form>
   <script type="text/javascript">
	$(document).ready(function() {
		$('#savecmd').click(function() {
		  if($('#USERNAME').attr('value')==''){
		  alert('请输入用户名');return;
		  }else  if($('#USERPASS').attr('value')==''){
		  alert('请输入用户名');return;
		  }else{
		    $("#frm").submit();
		  }
		});
		$('#cmdreturn').click(function() {
		window.history.back();
		});
	});
   </script>
   <% }else{%>
  【<span class="bt">会员管理</span>】
 《<a href="<%=basePath%>webadmin/member/user.jsp?act=a" title="添加新会员" rel="gb_page_center[600,200]">添加新会员</a>》
 <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
  <tr>
     <th  align="left">用户名</th>
     <th>真名</th>
     <th >电话</th>
     <th width="140">时间</th>
     <th width="140">操作</th>
  </tr>
  <% 
    
	    begin_no=(intPage-1) * intPageSize + 1; 
        end_no = intPage * intPageSize;
	    mysql="select * from (select rownum row_id ,mid,username,truename,telephone,addtime from (select mid,username,truename,telephone,addtime from web_member   order by mid desc))";
	    mysql=mysql+" where row_id between " +begin_no+ " and " +end_no;
	  // out.print(mysql);out.close();
	    ResultSet rs=con.getRs(mysql);
		int i=0;
		
		String suserid="";
		while(rs.next()){
		i++;
		suserid=rs.getString("mid");
	 %>
	<tr onmouseover='$(this).css({"background":"#cee1ed"});' onmouseout='$(this).css({"background":"#fff"});'>
    <td  width="140"><%=rs.getString("username") %></td>
    <td  align="center"><%=rs.getString("truename") %></td>
    <td  align="center"><%=rs.getString("telephone") %></td>
    <td width="140" align="center"><%=rs.getDate("addtime") %></td>
    <td width="140" align="center">
    <span class="area"><a  href="<%=basePath%>webadmin/member/user.jsp?act=e&page=<%=intPage %>&userid=<%=suserid%>"> 编辑 </a></span> 
    <span class="area"><a href="javascript:confirmDelete('<%=basePath%>webadmin/member/user.jsp?act=d&userid=<%=suserid%>&page=<%=intPage %>');"> 删除 </a></span></td>
    </tr>
   <%} 
   if(intPageCount>1){
   %>
   <tr>
    <td colspan="5" align="center">
     第<%=intPage%>页 共<%=intPageCount%>页 
<a href="<%=basePath%>webadmin/member/user.jsp?page=1">首页</a>
<%if(intPage>1){%><a href="<%=basePath%>webadmin/member/user.jsp?page=<%=intPage-1%>">上一页</a><%}%> 
<%if(intPage<intPageCount){%><a href="<%=basePath%>webadmin/member/user.jsp?page=<%=intPage+1%>">下一页</a><%}%> 
<a href="<%=basePath%>webadmin/member/user.jsp?page=<%=intPageCount%>">尾页</a>
   </td>
   </tr>
   <%} %>
 </table>
 <% } con.close();%>
  </body>
</html>
